package com.smbms.servlet;

import com.smbms.mapper.ProviderMapper;
import com.smbms.pojo.Bill;
import com.smbms.pojo.Provider;
import com.smbms.util.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ProviderServiceImpl implements ProviderService {

    @Resource
    private ProviderMapper providerMapper;


    @Override
    public PageBean<Provider> getPage(Map<String,Object> map) {
        /*查询总记录数，把起始页和每页显示数据存到工具类中*/
        PageBean<Provider> pageBean = new PageBean<Provider>();
        pageBean.setCurrentPage((Integer) map.get("pageIndex"));
        pageBean.setPageSize((Integer)map.get("pageSize"));
        map.put("startIndex",pageBean.getStartIndex());
        /*查询总记录数，并把总记录数的信息存储到工具类中*/
        pageBean.setTotalCount(providerMapper.getProviderCount());
        /*查询供应商所有信息*/
        pageBean.setResult(providerMapper.getProviderList(map));
        return pageBean;
    }

    @Override
    public boolean addProvider(Provider provider) {
        if(providerMapper.addProvider(provider) > 0){
            return true;
        }
        return false;
    }

    @Override
    public Provider getProviderById(Integer proid) {
        return providerMapper.getProviderById(proid);
    }

    @Override
    public int updateProvider(Provider provider) {
        return providerMapper.updateProvider(provider);
    }

    @Override
    public Bill selectBillById(Integer proid) {
        return providerMapper.selectBillById(proid);
    }

    @Override
    public int deleteProviderById(Integer proid) {
        return providerMapper.deleteProviderById(proid);
    }

    @Override
    public List<Provider> getProvider() {
        return providerMapper.getProvider();
    }
}
